Skip to main content

Last Update: 2025/3/26

Anthropic Completions API

The Anthropic Completions API allows you to generate text completions using Anthropic's language models. This document provides an overview of the API endpoints, request parameters, and response structure.

Endpoint

POST https://platform.llmprovider.ai/v1/complete

Request Headers

HeaderValue
x-api-keyYOUR_API_KEY
anthropic-version2023-06-01
Content-Typeapplication/json

Request Body

The request body should be a JSON object with the following parameters:

ParameterTypeDescription
max_tokens_to_sampleintegerThe maximum number of tokens to generate before stopping. Required range: x > 1
modelstringThe model that will complete your prompt. (e.g., claude-2.1).
promptstringThe prompt to complete.
metadataobject(Optional) An object describing metadata about the request.
stop_sequencesstring[](Optional) Sequences that will cause the model to stop generating.
streamboolean(Optional) Whether to stream the response using server-sent events.
temperaturenumber(Optional) Amount of randomness injected into the response. Required range: 0 < x < 1
top_knumber(Optional) Only sample from top K options. Required range: x > 0
top_pnumber(Optional) Use nucleus sampling. Required range: 0 < x < 1
max_tokensinteger(Optional) The maximum number of tokens to generate.

Example Request

{
"model": "claude-2.1",
"max_tokens_to_sample": 1024,
"prompt": "\n\nHuman: Hello, Claude\n\nAssistant:"
}

Response Body

The response body will be a JSON object containing the completion and metadata.

FieldTypeDescription
idstringUnique identifier for the completion.
modelstringThe model that handled the request.
completionstringThe generated completion text.
stop_reasonstringThe reason why the completion stopped.
typestringThe type of completion.

Example Response

{
"completion": " Hello! My name is Claude.",
"id": "compl_018CKm6gsux7P8yMcwZbeCPw",
"model": "claude-2.1",
"stop_reason": "stop_sequence",
"type": "completion"
}

Example Request

curl -X POST https://platform.llmprovider.ai/v1/complete \
-H "x-api-key: $YOUR_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-2.1",
"max_tokens_to_sample": 1024,
"prompt": "\n\nHuman: Hello, Claude\n\nAssistant:"
}'

For more details, refer to the Anthropic API documentation.